import {Link,hashHistory} from "react-router";

import store from "../../store/store";
var Tj = React.createClass({
	 componentWillMount(){
	 	//console.log(hashHistory);
	 	
	 },
	 cj:function(){ 
	 	
	 	
	   window.location.reload(true);
	  //hashHistory.push("/home/goods")
	  var shi = location.hash.indexOf("?")+10
		var mo = location.hash.indexOf("&") 
		var goodsid = location.hash.slice(shi,mo) 
		var url =  "http://www.chawo.com/mobile/index.php?act=goods&op=goods_detail&goods_id="+goodsid+"&key=&dis_id="
        		store.dispatch(function(dispatch , state){
    		fetch(url)
                .then(res=>res.json())
                .then(data=>{
                    dispatch({
                        type : "GOODS_QING",
                        content : data
                    })
                })
}) 
			setTimeout(function(){document.body.scrollTop=0},500)
			 
	 },
	render :function(){ 
		//to={"home/goods?goods_id="+this.props.data.goods_id} data-id={this.props.data.goods_id}
		return (
			<Link to={"home/goods?goods_id="+this.props.data.goods_id} data-id={this.props.data.goods_id} onClick={this.cj}>
				<img src ={this.props.data.goods_image_url}/>	
				<p>{this.props.data.goods_name}</p>
				<div>{this.props.data.goods_promotion_price}</div>
			</Link>
		)
	}
})

export default React.createClass({
	render : function(){ 
		var obj = this.props.data.map(function(data,index){
			return <Tj key={index} data={data}/>
		})
		return (
			<div className="goods_tuite">
				<h3>推荐</h3>
				{obj}
			</div>
		)
	}
})
